{extend name='../app/admin/view/common/block.html' /}

{block name="content"}
<style>
    .layui-table-cell{
        height:auto!important;
    }
</style>
<div class="layui-btn-container " style="display: inline-block;">
    <button id="btnDeleteChecked" class="layui-btn layui-btn-sm layui-btn-danger" j-href="{:plugin_url('delete')}">
        <i class="layui-icon">&#xe640;</i>删除
    </button>
    <button class="layui-btn layui-btn-sm j-open"
            j-href="{:plugin_url('create')}"
            j-title="新增商品标签"
            j-type="2"
            j-config='{"area":["80%","80%"],"anim":2}'
    >新增
    </button>
</div>


<table id="goods" lay-filter="goods"></table>

<script type="text/html" id="opera">
    <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</button>
</script>
{/block}

{block name="script"}
<script>
  layui.use(['layer','table'],function(){
      var table = layui.table
        , layer = layui.layer;

      table.render({
          elem:'#goods',
          url:'index',
          page:true,
          method:'post',
          height:'full-200',
          toolbar:true,
          cols:[[
              {type:'checkbox'}
              , {field: 'id', title: 'ID', width: 50}
              , {field: 'title', title: '标签名'}
              , {
                  field: "icon_path", title: "图标",width:100, templet: function (d) {
                      if (d.icon !== '') {
                          return '<div><img src="' + d.icon_path + '" width="100%" onclick="showImg(this)"/></div>';
                      } else {
                          return '-';
                      }
                  }
              }
              , {field: 'status', title: '状态',width:100,templet:function(d){
                      if(d.status == 1){
                          return '<span class="layui-badge layui-bg-green">显示</span>';
                      }else{
                          return '<span class="layui-badge">隐藏</span>';
                      }
                  }}
              , {field: 'sort', title: '排序值',width:100, sort: true}
              , {field: 'createtime', title: '创建时间', sort: true}
              , {title: '操作', templet: '#opera'}
          ]]
      });


      table.on('tool(goods)', function(obj){
          var data = obj.data;
          if(obj.event === 'del'){
              layer.confirm('确定执行删除操作', function(index){
                  layer.close(index);
                  $.get('delete', {id:data.id},function(r){
                      if(r.code == 1){
                          showpopup(r.msg);
                          obj.del();
                      }else{
                          showpopup(r.msg);
                      }
                  },'json')
              });
          } else if(obj.event === 'edit'){
              layer.open({
                  type:2,
                  title:'编辑',
                  shadeClose:true,
                  area:['80%','80%'],
                  content:'update?id='+data.id
              })
          }
      });
  })
</script>
{/block}